package situ.autoweter.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import situ.autoweter.service.RdVolumeService;
import situ.autoweter.entity.RdVolume;
import java.util.*;
/**
 * RdVolume的路由接口服务
 * 
 * @author 胡文
 *
 */
@Controller
public class RdVolumeController {

	/** RdVolumeService服务 */
	@Autowired
	private RdVolumeService rdVolumeService;
	
	/**
	 * 查询所有RdVolume数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryRdVolume", produces = {"application/json;charset=UTF-8"})
	public String find(RdVolume value,Map map) {
		 List<RdVolume> list= rdVolumeService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	/**
	 * 通过id查询RdVolume数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "queryRdVolumeById/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") Object id,Map map) {
        RdVolume obj=  rdVolumeService.findOne(id);
        map.put("RdVolume",obj);
        return "页面名称自己改";
	}
	
	/**
	 * 插入RdVolume属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "saveRdVolume", produces = {"application/json;charset=UTF-8"})
	public String save(RdVolume value) {
		  rdVolumeService.saveNotNull(value);
        return "redirect:/queryRdVolume";
	}
	
	/**
	 * 更新RdVolume属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateRdVolume", produces = {"application/json;charset=UTF-8"})
	public String update(RdVolume value) {
		  rdVolumeService.updateNotNullById(value);
          return "redirect:/queryRdVolume";
	}
	
	/**
	 * 通过id删除RdVolume数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "delRdVolumeById/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") Object id) {
		  rdVolumeService.deleteById(id);
          return "redirect:/queryRdVolume";
	}

	//超人易统计报表全查
	@RequestMapping(value = "rd_reportVolumeReading")
	public String find(Map map) {
		List<Map> list= rdVolumeService.Show();
		map.put("items",list);
		List<Map> years = rdVolumeService.queryYear();
		map.put("years", years);
		return "page/rd_reportVolumeReading";
	}

	//超人易根据年份查统计报表
	@RequestMapping(value = "query")
	public String query(String ReadYear, Model model) {
		List<Map> list;
		if(ReadYear!=null && !"".equals(ReadYear)) {
			list = rdVolumeService.query1(ReadYear);
			list.forEach(s-> System.out.println(s.toString()));
			model.addAttribute("items",list);

		}else {
			list= rdVolumeService.Show();
			list.forEach(s-> System.out.println(s.toString()));
			model.addAttribute("items",list);
		}
		model.addAttribute("ReadYear",ReadYear );
		//合计表册数量
		model.addAttribute("count", list.size());

		List<Map> years = rdVolumeService.queryYear();



		model.addAttribute("years", years);

		return "page/rd_reportVolumeReading";
	}
	//超人易周检报表全查
	@RequestMapping(value = "rd_reportMeterCheck")
	public String find2(Map map) {
		List<Map> list= rdVolumeService.find2();
		map.put("items",list);
		//合计水表数量
		map.put("Gj", list.size());
		return "page/rd_reportMeterCheck";
	}
	//超人易根据月龄查询周检报表
	@RequestMapping(value = "queryByYf", produces = {"application/json;charset=UTF-8"})
	public String queryByYF(Map map ,int number){
		List<Map> list=rdVolumeService.queryByYF(number);
		map.put("items",list );

		return "page/rd_reportMeterCheck";
	}


}
